package map.widget;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.util.prefs.Preferences;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import map.util.NodeConfig;

public class FloatablePanel extends JPanel {

	private Frame editor;
	private JComponent component;
	private JLabel label;
	private int perferenceID = 0;
	private Preferences pref;
	private int dividerSize = 0;
	private JDialog Dialogframe;

	public FloatablePanel(Frame editor, JComponent component, String title,
			String perferenceID) {
		this.editor = editor;
		this.component = component;
		label = new JLabel(title);
		pref = NodeConfig.getNode("dock/" + perferenceID);
		final JButton dialogbutton = new JButton("Float");
		dialogbutton.setAction(new AbstractAction() {

			@Override
			public void actionPerformed(ActionEvent e) {
				setFloating(true);

			}
		});
		JPanel topPanel = new HeaderPanel(new BorderLayout());
		topPanel.add(label, BorderLayout.WEST);
		topPanel.add(dialogbutton, BorderLayout.EAST);
		setLayout(new BorderLayout());
		add(topPanel, BorderLayout.NORTH);
		add(component, BorderLayout.CENTER);
		dividerSize = 0;
		Dialogframe = null;
	}

	private void setFloating(boolean flag) {

	}

	private class HeaderPanel extends JPanel {
		public HeaderPanel(BorderLayout borderLayout) {
			super(borderLayout);
			setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 1));
		}

		protected void paintComponent(Graphics g) {
			Color backgroundColor = new Color(200, 200, 240);
			g.setColor(backgroundColor);
			((Graphics2D) g).fill(g.getClip());
			g.setColor(backgroundColor.darker());
			g.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
		}
	}
}
